package com.shketai.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.shketai.entity.Interview;

public class InterviewDao {

private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	/**
	 * 新增面试学科
	 * @param interview
	 * @return
	 */
	public int add(Interview interview){
		Session session = sessionFactory.getCurrentSession();
		session.save(interview);
		return 1;
	}

	public int update(Interview interview){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Interview where id=:id");
		query.setInteger("id", interview.getId());
		List<Interview> list = query.list();
		Interview oldInterview = list.get(0);
		interview.setId(oldInterview.getId());
		//interview.setInterviewSubject(oldInterview.getInterviewSubject());
		session.clear();
		session.update(interview);
		return 1;
	}
	
	/**
	 * 查询面试科目
	 * @return
	 */
	public List<Interview>  findAllInterview(){
		Session session = sessionFactory.getCurrentSession();
		Query query = session.createQuery("from Interview");
		List<Interview> list = query.list();
		return list;
	}
}
